public class Base3 {

	String current_command;
	int current_step;
	int total_integer;
	int total_parentatis;
	int wanted_digit;
	int total_combination;
	
	Base3(int total_integer_input) 
	{
		
		total_integer  = total_integer_input;
		total_parentatis = total_integer - 1;
		wanted_digit = total_parentatis;
		current_step = 0;
		current_command = null;
		total_combination = getTotalCombination();
	}
		
	
	
	void displayCombination()
	{
      
		
		
		
	
		
		
		
		
		// compute starts
		


	
		
		 for(int i  = 0 ; i<  ((int) Math.pow(3, total_parentatis )  )  ; i++)
		{

			 System.out.println(    fillGap(  computeBase3(i), wanted_digit   )  );
		
		}
	   
	
	
	}
	
	int  getTotalCombination()
	{
      
		
		return (int)Math.pow(3, (total_integer-1) );
		
	}
	
	String  getCombinationAt(int combination_number)
	{
      
	  //first combination is 0th

			return    fillGap(  computeBase3(combination_number), wanted_digit   )  ;
		
	
	   
	
	
	}
	
	String getNextCombination()
	{
		//first combination is 0th
		if ( current_step < ((int) Math.pow(3, total_parentatis )  )  )
		{
			
			current_command = fillGap(  computeBase3(current_step), wanted_digit   );
			
			
		
		
			current_step++;
			
			return current_command;
		}
		
		else
		{
			return "";
		}
		
	}
		
 public  String fillGap(String input, int total_digit)
 {
	 String temp = "000000000000";
	 temp = temp + input;
	 
	 
	 temp = temp.substring( temp.length()-total_digit  );
	
	
	 return temp;
	
	 
 }
	
	
	
	public  String computeBase3(int input)
	{
		
		
		if (input!=0) // recursive case
		{
			computeBase3(input/3);
			
			return computeBase3(input/3) + (input%3);
			
		}		
		
		else 
		{
			return "";
		}
	}
	
	void resetCommand()
	{
		current_step=0;
	}
	
	
}